package edu.jd.homeworkteacher;

import edu.jd.homeworkstudent.HomeworkStudent;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface HomeworkTeaDao {

    @Insert("insert into homework_tea(hk_id, tea_id, hk_title, hk_req) values (#{hk_id}, #{tea_id}, #{hk_title}, #{hk_req})")
    public void insertHomework(@Param("hk_id")int hk_id,
                               @Param("tea_id") String tea_id,
                               @Param("hk_title") String hk_title,
                               @Param("hk_req") String hk_req);

    @Select("select max(hk_id) from homework_tea")
    public Integer getMaxHomeworkId();

    @Insert("insert into homework_stu(hk_id, stu_id, hk_submit, tea_feedback, score, correct_state, submit_state)" +
            "values (#{hk_id}, #{stu_id}, #{hk_submit}, #{tea_feedback}, #{score}, #{correct_state}, #{submit_state} )")
    public void insertHomeworkToStudent(HomeworkStudent student);

    @Select("select stu_id from stu_tea where tea_id = #{tea_id}")
    public List<String> getMyStudentId(String tea_id);

    @Select("select hk_title, hk_submit, homework_stu.hk_id, stu_id " +
            "from homework_stu, homework_tea " +
            "where homework_tea.tea_id = #{tea_id} " +
            "and submit_state = true " +
            "and correct_state = false")
    public List<CorrectHomeworkDto> getStudentsHomework(String tea_id);

    @Update("update homework_stu " +
            "set tea_feedback = #{tea_feedback}, score = #{score}, correct_state = true " +
            "where hk_id = #{hk_id} and stu_id = #{stu_id}")
    public void updateCorrectHomework(@Param("hk_id") int hk_id,
                                      @Param("stu_id") String stu_id,
                                      @Param("score") int score,
                                      @Param("tea_feedback") String tea_feedback);
}
